// const { createServer } = require("node:http");
import { createServer } from "node:http";

const hostname = "127.0.0.1";
const port = 3000;

const server = createServer((req, res) => {
  // console.log("输出: req.header", req.headers);
  console.log("输出: req.url", req.url);
  console.log("输出: req.method", req.method);

  if (req.url.includes("/test")) {
    res.statusCode = 200;
    res.setHeader("Content-type", "text/plain");
    res.end("<h1>test</h1>");
    return;
  }
  res.statusCode = 200;
  res.setHeader("Content-type", "text/plain");
  res.end("Hello, world");
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
